package mlp.game.scootaloo;

import com.overkill.game.GameEngine;
import com.overkill.game.Renderable;
import com.overkill.game.Sprite;
import com.overkill.game.SpriteRenderable;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;

public class Obstacle extends SpriteRenderable {
	public enum Type{ OBSTACLE, CUPCAKE, DERPY};
	
	private Type type;
	private Shadow shadow;
	private float movementModifier = 0;
	
	public Obstacle(Sprite[] sprite, Type type, float ground, Paint shadowPaint) {
		super(sprite[(int) (Math.random() * sprite.length)]);
		this.type = type;
		if(type == Type.OBSTACLE){
			this.shadow = new Shadow(this, ground, 1, 0, GameEngine.dip(14.6f), shadowPaint);
			this.shadow.setSize(getWidth() * 1.05f, GameEngine.dip(16));
			this.moveTo(GameEngine.getStage().width(), ground - getHeight());
		} else if(type == Type.CUPCAKE){
			this.shadow = new Shadow(this, ground, 1, 0, GameEngine.dip(5.3f), shadowPaint);
			this.shadow.setSize(getWidth() * 1.05f, GameEngine.dip(8));		
			this.moveTo(GameEngine.getStage().width(), ground - getHeight());
		} else if(type == Type.DERPY){
			this.shadow = new Shadow(this, ground, 1, 0, GameEngine.dip(5.3f), shadowPaint);
			this.shadow.setSize(getWidth() * 1.05f, GameEngine.dip(8));	
			this.moveTo(GameEngine.getStage().width(), GameEngine.dip(10));
			this.movementModifier = -GameEngine.dip(2f);
		}
	}

	@Override
	public void update(long gameTime) {
		moveXBy(-ScootalooEngine.GAME_SPEED - movementModifier);
		super.update(gameTime);
		this.shadow.update();
	}
	
	@Override
	public void draw(Canvas canvas) {
		this.shadow.draw(canvas);
		super.draw(canvas);
	}
	
	public void setType(Type type) {
		this.type = type;
	}

	public Type getType() {
		return type;
	}
	
	@Override
	public boolean isHit(Renderable r) {
		if(RectF.intersects(r.getFrame(), new RectF(getFrame().left, getFrame().top + 2, getFrame().left + 1, getFrame().bottom)) ||
		   RectF.intersects(r.getFrame(), new RectF(getFrame().right, getFrame().top + 2, getFrame().right - 1, getFrame().bottom)))
			return true;		
		return false;
	}
}
